package com.example.ceramics;

import android.content.Context;
import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.example.ceramics.database.dao.GoodsDaoImpl;
import com.example.ceramics.database.dao.IGoodsDao;
import com.example.ceramics.database.dao.IUserDao;
import com.example.ceramics.database.dao.UserDaoImpl;
import com.example.ceramics.entity.GoodsEntity;
import com.example.ceramics.entity.UserEntity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
public class TestGoods {
    private IGoodsDao goodsDao;

    @Before
    public void testPrepare() {
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        goodsDao = new GoodsDaoImpl(appContext);
    }

    @Test
    public void testAddGoods() {
        GoodsEntity goods = new GoodsEntity();
        goods.setGoodsName("陶瓷");
        goods.setGoodsPrice(3);
        goods.setGoodsSignature("可以的");
        goods.setGoodsType("十二生肖系列");
        goods.setGoodsImg(R.mipmap.image2);
        int result = goodsDao.addGoods(goods);
        Log.d("aaa", "addUser result:" + result);
        assertEquals(1, result);
    }

    @Test
    public void testDeleteGoods(){
        int result = goodsDao.deleteGoods(1);
        assertEquals(result,1);
    }

    @Test
    public void testUpdateGoods(){
        GoodsEntity goods = new GoodsEntity(1,"第一个",11,"修改第一个","十二生肖系列",R.mipmap.image1);
        int result = goodsDao.updateGoods(goods);
        assertEquals(result,1);
    }

    @Test
    public void testGetGoods(){
        GoodsEntity goods = goodsDao.getGoods(1);
        Log.d("aaa","result:"+goods);
    }

    @Test
    public void testListAllGoods(){
        List<GoodsEntity> goodsList = goodsDao.listAllGoods();
        for (GoodsEntity goods : goodsList) {
            Log.d("aaa","result:"+goods);
        }
    }

    @Test
    public void testListGoodsByType(){
        List<GoodsEntity> goodsList = goodsDao.listGoodsByType("十二生肖系列");
        for (GoodsEntity goods : goodsList) {
            Log.d("aaa","result:"+goods);
        }
    }

    @Test
    public void testAddAllGoods(){
        goodsDao.addAllGoods();
    }
}
